﻿<html>
    <head>
        <title>Médiathèque - Consultation</title>
        <?php include('communs/lienCss.php'); 
		function translatestatus($str){
			switch ($str){
				case 'D':
					return 'Disponible';
				case 'B':
					return 'Brisé';
				case 'R':
					return 'Réservé';
				case 'E':
					return 'Emprunté';
				case 'O':
					return 'Retiré de l\'inventaire';
				default:
					return $str;
			}
		}
		function show($k, $v){
			switch ($k){
				case 'idDisque':
					$sql="select titre from disque where id=$v";
					$result = mysql_query($sql);
					$row = mysql_fetch_array($result);
					$k = "disque";
					$v = "<a href='http://localhost/mmediatheque/item.php?no=$v'>".$row[0]."</a>";
					break;
				case 'idFilm':
					$sql="select titre from film where id=$v";
					$result = mysql_query($sql);
					$row = mysql_fetch_array($result);
					$k = "film";
					$v = "<a href='http://localhost/mmediatheque/item.php?no=$v'>".$row[0]."</a>";
					break;
				case 'anneePublication':
					$k = "année de publication";
					break;
				case 'duree':
					$k = "durée";
					break;
				case 'etiquette':
					$k = "étiquette";
					break;
				case 'sousTitre':
					$k = "sous-titre";
					break;
				case 'codeBarre':
					$k = "code barre";
					break;
				case 'idColl':
					$sql="select nom from collection where id=$v";
					$result = mysql_query($sql);
					if ($result) {
						$row = mysql_fetch_array($result);
						$v = "<a href='http://localhost/mmediatheque/recherche.php?mode=tous&champ=idColl&input=".$row[0]."&page=1'>".$row[0]."</a>";
					}
					$k = "collection";
					break;
				case 'noVolume':
					$k = "numéro de volume";
					break;
				case 'idOriginal':
					$sql="select titre from disque where id=$v";
					$result = mysql_query($sql);
					if ($result) {
						$row = mysql_fetch_array($result);
						$v = "<a href='http://localhost/mmediatheque/item.php?no=$v'>".$row[0]."</a>";
					}
					$k = "disque original";
					break;
				case 'editeur':
					$k = "éditeur";
					break;
				case 'idPiste':
					if ($v) {
						$v = "<a href='http://localhost/mmediatheque/item.php?no=$v'>Piste audio</a>";
					}
					$k = "piste";
					break;
				case 'noPiste':
					$k = "numéro de piste";
					break;
				case 'annee':
					$k = "année";
					break;
				case 'epoque':
					$k = "époque";
					break;
				case 'tonalite':
					$k = "tonalité";
					break;
				case 'idDocument':
					if ($v) {
						$v = "<a href='http://localhost/mmediatheque/item.php?no=$v'>Partition</a>";
					}
					$k = "partition";
					break;
			}
			echo "<tr><td>$k :</td><td>$v</td></tr>\n";
		}
		?>
        <script type="text/javascript" src="js/dropdown/jquery.js"></script>
    </head>
    <body>
        <div id="conteneurTete">
            <?php include('communs/enTete.php');?>
        </div> 
            
        <?php 
            $con = mysql_connect('localhost','root','');

            if (!$con){
                die("Unable to connect to MySQL");
            }

            mysql_select_db('mediatheque');
			include('communs/menu.php'); ?>
        <div id="conteneurCorps">
			<?php
			//trouve le type de l'item
			if (isset($_GET['no'])) {
				$id = $_GET['no'];
				$sql = "select 'disque' from disque where id=$id UNION select 'document' from document where id=$id UNION select 'film' from film where id=$id UNION select 'piste' from piste where id=$id UNION select 'episode' from episode where id=$id";
				$result = mysql_query($sql);
				if ($result){
					if (mysql_num_rows($result)>0){
						$type = mysql_fetch_array($result);
						$type = $type[0];
						echo "<br/><br/>";
						$sql = "select * from $type where id=$id";
						$result = mysql_query($sql);
						$row = mysql_fetch_assoc($result);
						$codebarre = $row['codeBarre'];
						if ($result["image"]){
							echo "<img src='".$result["image"]."' />";
						}
						echo "<table border=0>";
						foreach ($row as $key => $value) {
							if ($key <> "image" and $key <> "codeBarre"){
								show($key, $value);
							}
						}
						echo "</table>";
						
						$sql2 = "select id, status from exemplaire where idMedia=$id";
						$result2 = mysql_query($sql2);
						if($result2){
							echo "<br /><br /><table border=1>\n";
							echo "<caption>Exemplaires</caption>\n";
							while ($row2 = mysql_fetch_array($result2)){
								echo "<tr>\n";
								if (strlen($row2["id"])==1) {
									echo "<td>".$codebarre."0".$row2['id']."</td>\n";
								}else{
									echo "<td>".$codebarre."0".$row2['id']."</td>\n";
								}
								echo "<td>".translatestatus($row2['status'])."</td>";
								echo "<tr/>\n";
								
							}
							echo "</table>";
                            echo "<input type='button' value='Réserver' /><br /><br />";
						}
					}else{
						echo "id non trouvé<br/><br/>";
					}
				}
			}else{
				echo "Si vous connaissez le numéro de l'item, entrez ?no=<i>numéro de l'item</i>. Sinon, passez par la fenêtre de recherche. <br/><br/>";
			}
			?>
            <a href="index.php">Retour</a>
        </div>
        <div id="conteneurPied">
            <?php include('communs/piedDePage.php'); ?>
        </div>
    </body>
</html>
